package com.zhhs.galaxyott.httpVolley.parser;

import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;
import android.util.Log;

import com.zhhs.galaxyott.httpVolley.response.MovieDetailResponse;

public class MovieDetailParser extends BaseParser<MovieDetailResponse> {

    @Override
    public MovieDetailResponse parse(String jsonString) {
        MovieDetailResponse response = new MovieDetailResponse();

        try {
            // 如果用fastobjson就是此处不同
            // JSONObject obj = JSON.parseObject(paramString);
            JSONObject obj = new JSONObject(jsonString);
            parseMsg(obj, response);

            // 先判断返回码.
            int errCode = obj.getInt("errCode");
            response.errCode = errCode;
            String returnCode = String.valueOf(errCode);

            if (TextUtils.isEmpty(returnCode)) {
                return null;
            }
            Log.i("DEBUG_LC", "THIS IS returnCode != 0");
            if (returnCode.equals("0")) {// 返回正常.

                response.Beans.setIdentify(obj.optString("identify"));
                response.Beans.setImgurl(obj.optString("imgurl"));
                response.Beans.setName(obj.optString("name"));
                response.Beans.setEname(obj.optString("ename"));
                response.Beans.setScore(obj.optDouble("score"));
                response.Beans.setDirector(obj.optString("director"));
                response.Beans.setActor(obj.optString("actor"));
                response.Beans.setIntro(obj.optString("intro"));
                response.Beans.setIsFavorite(obj.optInt("isFavorite"));
                response.Beans.setIsAuthed(obj.optInt("isAuthed"));
                response.Beans.setIsRated(obj.optInt("isRated"));
                response.Beans.setRating(obj.optInt("rating"));
                response.Beans.setIsPraised(obj.optInt("isPraised"));
                response.Beans.setPraiseNum(obj.optInt("praiseNum"));
                response.Beans.setPrice(obj.optDouble("price"));
                if (obj.has("mediaid")) {
                    response.Beans.setMediaid(obj.optString("mediaid"));
                }
                if (obj.has("preview")) {
                    response.Beans.setPreview(obj.optString("preview"));
                }
                response.Beans.setPrice(obj.optDouble("price"));
                response.Beans.setWatchNum(obj.optInt("watchNum"));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return response;
    }

}
